//
//  EditDetailView.m
//  Comma
//
//  Created by 杜远洋 on 15-1-20.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "EditDetailView.h"
#import "GlobalMacro.h"
#import "GlobalMethod.h"
#import "EditCustomView.h"
#import "AFNetWorkingYU.h"
#import "URLMacro.h"
#import "EditDetailModel.h"

@implementation EditDetailView

- (instancetype)initWithLeftButton:(NSString *)leftTitle RightButton:(NSString *)rightTitle Title:(NSString *)title FooterView:(FooterViewState)footer
{
    self = [super initWithLeftButton:leftTitle RightButton:rightTitle Title:title FooterView:footer];
    if (self) {
        self.textArray = [NSMutableArray array];
    }
    return self;
}

- (void)createMyEditDetail
{


    [self setBackgroundColor:[UIColor whiteColor]];
    [self schoolInformation];
    [self personalInformation];
    [self personalSchoolInformation];
    [self otherInformation];
    [self createMyGradeData];
    [self createMyBirthData];
    [self createBirthPicker];
    [self createGradePicker];

}
//赋值过后通过属性的get方法 刷新控件
- (void)setMyDic:(NSDictionary *)myDic
{
    _myDic = myDic;
    [self createMyEditDetail];
}
- (void)schoolInformation
{
    self.myButton = [[UIButton alloc] initWithFrame:CGRectMake(16, 64, SCREEN_WIDTH - 16, 44)];
 
    [self.myButton setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:self.myButton];
    
    self.colleage = [[UILabel alloc] initWithFrame:CGRectMake(0, 12, 30, 20)];

    [self.colleage setBackgroundColor:[UIColor clearColor]];
    [self.colleage setText:@"学校"];
    [self.colleage setFont:[UIFont systemFontOfSize:14]];
    [self.colleage setTextColor:REDCOLOR];
    [self.myButton addSubview:self.colleage];
    
    self.schoolButton = [[UIButton alloc] initWithFrame:CGRectMake(45, 12, 270, 20)];
    if (iPhone6Plus) {
        [self.schoolButton setFrame:CGRectMake(45, 12, 309, 20)];
    }
    [self.schoolButton setBackgroundColor:[UIColor clearColor]];
    [self.schoolButton setTitle:[self.myDic objectForKey:@"school"] forState:UIControlStateNormal];
    [self.schoolButton setTitleColor:BLACKCOLOR forState:UIControlStateNormal];
    self.schoolButton.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.schoolButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [self.myButton addSubview:_schoolButton];
    
    UIImageView *toRight = [[UIImageView alloc] initWithFrame:CGRectMake(315, 0, 44, 44)];
    if (iPhone6Plus) {
        [toRight setFrame:CGRectMake(354, 0, 44, 44)];
    }
    [toRight setImage:[UIImage imageNamed:@"Button_updown_open"]];
    toRight.transform = CGAffineTransformMakeRotation(M_PI_2);
    [self.myButton addSubview:toRight];
    [self schoolSeperateLine];
}
- (void)schoolSeperateLine
{
    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, 108) EndPoint:CGPointMake(SCREEN_WIDTH, 108) inUIView:self];
  
}


- (void)personalInformation
{
    
    self.myHeight = [self getHeightOfProfile];
//    if (iPhone6Plus) {
//        if (self.myHeight > 30) {
//            self.myHeight = 60;
//            self.secondLineHeight = 379.5;
//            self.thirdLineHeight = 627;
//        }
//        else
//        {
//            self.myHeight = 30;
//            self.secondLineHeight = 349.5;
//            self.thirdLineHeight = 597;
//        }
//
//    }
    
    if (self.myHeight > 20) {
        self.myHeight = 40;
        self.secondLineHeight = 253;
        self.thirdLineHeight = 418;
    }
    else
    {
        self.myHeight = 20;
        self.secondLineHeight = 233;
        self.thirdLineHeight = 398;
    }

    self.upView = [[UIView alloc] initWithFrame:CGRectMake(16, 108, SCREEN_WIDTH - 16, self.secondLineHeight - 108)];
//    if (iPhone6Plus) {
//        self.upView.frame = CGRectMake(24, 162, SCREEN_WIDTH - 24, self.secondLineHeight - 162);
//    }
    [self.upView setBackgroundColor:[UIColor clearColor]];
    [self addSubview:self.upView];
    
    NSArray *titleArray = [NSArray arrayWithObjects:@"姓名", @"性别", @"简介", nil];

    for (int i = 0; i < 3; i++) {
        UILabel *titleView = [[UILabel alloc] initWithFrame:CGRectMake(0, 10 + 37 * i, 100, 15)];
#pragma mark - 关于适配问题  修改不对的地方就可以了。
        [titleView setBackgroundColor:[UIColor clearColor]];
        [titleView setText:[titleArray objectAtIndex:i]];
        [titleView setFont:[UIFont systemFontOfSize:11]];
        [titleView setTextColor:TEXTGREENCOLOR];
        [self.upView addSubview:titleView];
    }
    
    self.name = [[UITextField alloc] initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH - 32, 20)];
    [self.name setText:[self.myDic objectForKey:@"nick"]];
    [self.name setFont:[UIFont systemFontOfSize:14]];
    [self.name setTextColor:BLACKCOLOR];
    self.name.delegate = self;
    self.name.tag = 102;
    [self.upView addSubview:self.name];

    self.sex = [[UIButton alloc] initWithFrame:CGRectMake(0, 62,  SCREEN_WIDTH - 32, 20)];
    [self.sex setTitle:[self.myDic objectForKey:@"gender"] forState:UIControlStateNormal];
    self.sex.titleLabel.font = [UIFont systemFontOfSize:14];
#pragma mark - 用tag值标记性别  然后去改变它 
#pragma mark - 惊奇的发现  一个button可以走多个action方法  而且 多个button也可以走同一个方法  噢耶~！
//    [self.sex addTarget:self action:@selector(buttonSexAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.sex setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [self.sex setTitleColor:BLACKCOLOR forState:UIControlStateNormal];
    [self.upView addSubview:self.sex];

        NSLog(@"%f",self.myHeight);
    self.shortIntroduction = [[UITextView alloc] initWithFrame:CGRectMake(-3, 99, SCREEN_WIDTH - 32, self.myHeight)];
    [self.shortIntroduction setText:[self.myDic objectForKey:@"profile"]];
    [self.shortIntroduction setBackgroundColor:[UIColor clearColor]];
    [self.shortIntroduction setTextAlignment:NSTextAlignmentLeft];
    [self.shortIntroduction setTextColor:BLACKCOLOR];
    [self.shortIntroduction setFont:[UIFont systemFontOfSize:14]];
    //调整容器的坐标  容器的里面放的是输入的内容
    [self.shortIntroduction setTextContainerInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    self.shortIntroduction.scrollEnabled = NO;
    self.shortIntroduction.delegate = self;
//    self.shortIntroduction.contentSize = CGSizeMake(SCREEN_WIDTH - 32, 32);
    [self.upView addSubview:self.shortIntroduction];
    
//    self.secondLineHeight = 233;
//
    [self personalSeperateLine];
}

- (void)textViewDidChange:(UITextView *)textView
{
    
    if (self.textArray != nil||[self.textArray count] != 0) {
        if (![self.myInputText isEqualToString:[self.textArray lastObject]] && self.myInputText != nil) {
            NSLog(@"%@", self.myInputText);
            textView.text  = self.myInputText;
        }
    }
    [self.textArray addObject:textView.text];
    
}

#pragma mark - 限制输入内容长度 扩展输入文本框的高度
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    //监控光标的换行(根据光标换行 来加高高度)
    CGPoint cursorPosition = [textView caretRectForPosition:textView.selectedTextRange.start].origin;
    NSLog(@"y = %f , x = %f", cursorPosition.y, cursorPosition.x);
//    NSLog(@"11111 = %@", textView.text);//当前的文本
//    NSLog(@"22222 = %@",text);//当前输入的字符
   
//    限制输入64个字符
    
    //通过光标的位置来控制我输入的文本的多少，真是so easy啊
    if (iPhone5) {
        self.maxLength = 255;
        
    }
    if (iPhone6) {
        self.maxLength = 310;

    }
    if (iPhone6Plus) {
        self.maxLength = 365;
    }
    //监控文本长度  如果超长 那么保持最大长度
    NSLog(@"%@", textView.text);
    
    if (cursorPosition.y > 1 && cursorPosition.y < 20 && cursorPosition.x > self.maxLength) {
        if ([text isEqualToString:@""]) {
        
            if (cursorPosition.y != - 1.0) {
                
                [textView setFrame:CGRectMake(0, 99, SCREEN_WIDTH - 32, 40)];
                
                self.upView.frame = CGRectMake(16, 108, SCREEN_WIDTH - 16, 145);
                self.secondLineHeight = 253;
                self.thirdLineHeight = 418;
                
                self.downView.frame = CGRectMake(16, self.secondLineHeight, SCREEN_WIDTH - 16, SCREEN_HEIGHT - 213);
#pragma mark - 移除分割线 添加新的分割线（分割线的坐标更改了）
                UIImageView *seperateLineSecond = (UIImageView *)[self viewWithTag:150];
                UIImageView *seperateLineThird = (UIImageView *)[self viewWithTag:110];
                [seperateLineSecond removeFromSuperview];
                [seperateLineThird removeFromSuperview];
                [self personalSeperateLine];
                [self personalSchoolSeperateLine];
                
                
            }
            else
            {
                [textView setFrame:CGRectMake(0, 99, SCREEN_WIDTH - 32, 20)];
                
                self.upView.frame = CGRectMake(16, 108, SCREEN_WIDTH - 16, 125);
                self.secondLineHeight = 233;
                self.thirdLineHeight = 398;
                
                self.downView.frame = CGRectMake(16, self.secondLineHeight, SCREEN_WIDTH - 16, SCREEN_HEIGHT - 233);
#pragma mark - 移除分割线 添加新的分割线（分割线的坐标更改了）
                UIImageView *seperateLineSecond = (UIImageView *)[self viewWithTag:150];
                UIImageView *seperateLineThird = (UIImageView *)[self viewWithTag:110];
                [seperateLineSecond removeFromSuperview];
                [seperateLineThird removeFromSuperview];
                [self personalSeperateLine];
                [self personalSchoolSeperateLine];
                
            }

        }
        else
        {
            return NO;
        }
        
    }
    
    if (cursorPosition.y != - 1.0 && cursorPosition.y < 20) {
        
        [textView setFrame:CGRectMake(0, 99, SCREEN_WIDTH - 32, 40)];
        
        self.upView.frame = CGRectMake(16, 108, SCREEN_WIDTH - 16, 145);
        self.secondLineHeight = 253;
        self.thirdLineHeight = 418;
        
        self.downView.frame = CGRectMake(16, self.secondLineHeight, SCREEN_WIDTH - 16, SCREEN_HEIGHT - 213);
#pragma mark - 移除分割线 添加新的分割线（分割线的坐标更改了）
        UIImageView *seperateLineSecond = (UIImageView *)[self viewWithTag:150];
        UIImageView *seperateLineThird = (UIImageView *)[self viewWithTag:110];
        [seperateLineSecond removeFromSuperview];
        [seperateLineThird removeFromSuperview];
        [self personalSeperateLine];
        [self personalSchoolSeperateLine];
        
       
    }
    else 
    {
        [textView setFrame:CGRectMake(0, 99, SCREEN_WIDTH - 32, 20)];
        
        self.upView.frame = CGRectMake(16, 108, SCREEN_WIDTH - 16, 125);
        self.secondLineHeight = 233;
        self.thirdLineHeight = 398;
        
        self.downView.frame = CGRectMake(16, self.secondLineHeight, SCREEN_WIDTH - 16, SCREEN_HEIGHT - 233);
#pragma mark - 移除分割线 添加新的分割线（分割线的坐标更改了）
        UIImageView *seperateLineSecond = (UIImageView *)[self viewWithTag:150];
        UIImageView *seperateLineThird = (UIImageView *)[self viewWithTag:110];
        [seperateLineSecond removeFromSuperview];
        [seperateLineThird removeFromSuperview];
        [self personalSeperateLine];
        [self personalSchoolSeperateLine];
   

    }

//汉字和英文的不同  还需更改 需要真机测试
    
   
    return YES;
}

- (void)personalSeperateLine
{
    NSLog(@"seperateLine = %uld",self.secondLineHeight);
    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, self.secondLineHeight) EndPoint:CGPointMake(SCREEN_WIDTH, self.secondLineHeight) inUIView:self myTag:150];
}

- (void)personalSchoolInformation
{
    self.downView = [[UIView alloc] initWithFrame:CGRectMake(16, self.secondLineHeight, SCREEN_WIDTH - 16, SCREEN_HEIGHT - self.secondLineHeight)];
    [self.downView setBackgroundColor:[UIColor clearColor]];
    [self addSubview:self.downView];
    
    UIView *personalSchoolView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 16, 165)];
    [personalSchoolView setBackgroundColor:[UIColor clearColor]];
    [self.downView addSubview:personalSchoolView];
    
    NSArray *titleArray = [NSArray arrayWithObjects:@"系别", @"专业", @"年级", @"学号",nil];
    for (int i = 0; i < 4; i++) {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10 + 37 * i, 100, 15)];
        [titleLabel setBackgroundColor:[UIColor clearColor]];
        [titleLabel setText:[titleArray objectAtIndex:i]];
        [titleLabel setFont:[UIFont systemFontOfSize:11]];
        [titleLabel setTextColor:TEXTGREENCOLOR];
        [personalSchoolView addSubview:titleLabel];
    }
    
    self.department = [[UITextField alloc] initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH - 32, 20)];
    [self.department setText:[self.myDic objectForKey:@"dept"]];
    [self.department setFont:[UIFont systemFontOfSize:14]];
    [self.department setTextColor:BLACKCOLOR];
    self.department.delegate = self;
    self.department.tag = 100;
    [self.downView addSubview:self.department];
    
    self.major = [[UITextField alloc] initWithFrame:CGRectMake(0, 62, SCREEN_WIDTH - 32, 20)];
    [self.major setText:[self.myDic objectForKey:@"major"]];
    [self.major setFont:[UIFont systemFontOfSize:14]];
    [self.major setTextColor:BLACKCOLOR];
    self.major.delegate = self;
    self.major.tag = 101;
    [self.downView addSubview:self.major];
    
    self.grade = [[UIButton alloc] initWithFrame:CGRectMake(0, 99, SCREEN_WIDTH - 32, 20)];
    [self.grade setTitle:[self.myDic objectForKey:@"grade"] forState:UIControlStateNormal];
    self.grade.titleLabel.font = [UIFont systemFontOfSize:14];
    [self.grade setTitleColor:BLACKCOLOR forState:UIControlStateNormal];
    self.grade.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.grade addTarget:self action:@selector(theirButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.grade.tag = 124;
    [self.downView addSubview:self.grade];
    
    self.studentNumber = [[UITextField alloc] initWithFrame:CGRectMake(0, 136, SCREEN_WIDTH - 32, 20)];
    [self.studentNumber setText:[self.myDic objectForKey:@"sNum"]];
    [self.studentNumber setFont:[UIFont systemFontOfSize:14]];
    [self.studentNumber setTextColor:BLACKCOLOR];
    self.studentNumber.tag = 103;
    [self.downView addSubview:self.studentNumber];
    self.studentNumber.delegate = self;
    
//    self.thirdLineHeight = 398;
    
    [self personalSchoolSeperateLine];
}
- (void)personalSchoolSeperateLine
{
    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, self.thirdLineHeight) EndPoint:CGPointMake(SCREEN_WIDTH, self.thirdLineHeight) inUIView:self myTag:110];
}

- (void)otherInformation
{
    UIView *otherView = [[UIView alloc] initWithFrame:CGRectMake(0, 165, SCREEN_WIDTH - 16, 500)];
    if (iPhone5) {
        [otherView setFrame:CGRectMake(0, 160, SCREEN_WIDTH - 16, 220)];
    }
    [otherView setBackgroundColor:[UIColor whiteColor]];
    [self.downView addSubview:otherView];
    
    NSArray *titleArray = [NSArray arrayWithObjects:@"生日", @"QQ", @"擅长", @"爱好",nil];
    for (int i = 0; i < 4; i++) {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 10 + 37 * i, 100, 15)];
        
        [titleLabel setBackgroundColor:[UIColor clearColor]];
        [titleLabel setText:[titleArray objectAtIndex:i]];
        [titleLabel setFont:[UIFont systemFontOfSize:11]];
        [titleLabel setTextColor:TEXTGREENCOLOR];
        [otherView addSubview:titleLabel];
    }

    
    self.birthday = [[UIButton alloc] initWithFrame:CGRectMake(0, 25, SCREEN_WIDTH - 32, 20)];
    [self.birthday.titleLabel setFont:[UIFont systemFontOfSize:14]];
    [self.birthday setTitleColor:BLACKCOLOR forState:UIControlStateNormal];
    self.birthday.tag = 125;
    self.birthday.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.birthday addTarget:self action:@selector(theirButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [otherView addSubview:self.birthday];
    
    self.qq = [[UITextField alloc] initWithFrame:CGRectMake(0, 62, SCREEN_WIDTH - 32, 20)];
    [self.qq setFont:[UIFont systemFontOfSize:14]];
    [self.qq setTextColor:BLACKCOLOR];
    [self.qq setText:[self.myDic objectForKey:@"qq"]];
    self.qq.delegate = self;
    [otherView addSubview:self.qq];
    
    //擅长
    self.specialty = [[UITextField alloc] initWithFrame:CGRectMake(0, 99, SCREEN_WIDTH - 32, 20)];
    
    [self.specialty setFont:[UIFont systemFontOfSize:14]];
    [self.specialty setTextColor:BLACKCOLOR];
    self.specialty.delegate = self;
    [self.specialty setText:[self.myDic objectForKey:@"specialty"]];
    [otherView addSubview:self.specialty];
    
    //爱好
    self.interest = [[UITextField alloc] initWithFrame:CGRectMake(0, 136, SCREEN_WIDTH - 32, 20)];
    if (iPhone5) {
        [self.interest setFrame:CGRectMake(0, 132, SCREEN_WIDTH -  32, 20)];
    }
    [self.interest setBackgroundColor:[UIColor clearColor]];
    [self.interest setFont:[UIFont systemFontOfSize:14]];
    [self.interest setTextColor:BLACKCOLOR];
    self.interest.tag = 501;
    [self.interest setText:[self.myDic objectForKey:@"interest"]];
    self.interest.delegate = self;
    [otherView addSubview:self.interest];
    
    
    //分割线 舍弃
    //[self otherSeperateLine];
}
- (void)otherSeperateLine
{
    [GlobalMethod drawLineWithStartPoint:CGPointMake(16, 618) EndPoint:CGPointMake(SCREEN_WIDTH, 618) inUIView:self];
}

#pragma mark - 设置选项卡  选择性别 用uiActionSheet    pickerview颜色#252525

- (void)buttonSexAction:(id)sender
{
    NSLog(@"action Sheet");
    [self viewMoveToOrigin];
    [self endEditing:YES];
    [self hideMyPicker];
   
       
}







#pragma mark - 创建年级的pickerView   创建生日的pickerView
- (void)createGradePicker
{
    self.gradePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, 162)];
    self.gradePicker.delegate = self;
    self.gradePicker.dataSource = self;
    self.gradePicker.showsSelectionIndicator = YES;
    [self.gradePicker setBackgroundColor:[UIColor colorWithRed:37/255.0f green:37/255.0f blue:37/255.0f alpha:1]];
    if ([self.myDic objectForKey:@"grade"]) {
        [self.grade setTitle:[self.myDic objectForKey:@"grade"] forState:UIControlStateNormal];
    }
    else
    {
        [self.grade setTitle:[self.gradeArray firstObject] forState:UIControlStateNormal];
    }
    
}
- (void)createBirthPicker
{
    self.birthPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, 162)];
    self.birthPicker.delegate = self;
    self.birthPicker.dataSource = self;
      self.birthPicker.showsSelectionIndicator = YES;
    [self.birthPicker setBackgroundColor:[UIColor colorWithRed:37/255.0f green:37/255.0f blue:37/255.0f alpha:1]];
    
    //给picker赋值 初始值
    NSString *myBirth = [NSString stringWithFormat:@"%@-%@-%@", [[self.birthArray firstObject] firstObject], [[self.birthArray objectAtIndex:2] firstObject], [[self.birthArray lastObject] firstObject]];
    myBirth = [myBirth stringByReplacingOccurrencesOfString:@"年" withString:@""];
    myBirth = [myBirth stringByReplacingOccurrencesOfString:@"月" withString:@""];
    myBirth = [myBirth stringByReplacingOccurrencesOfString:@"日" withString:@""];
    if ([self.myDic objectForKey:@"birth"]) {
        [self.birthday setTitle:[self.myDic objectForKey:@"birth"] forState:UIControlStateNormal];
    }
    else
    {
        [self.birthday setTitle:myBirth forState:UIControlStateNormal];
    }
}
- (void)createMyToolBar:(UIPickerView *)myPick
{
    self.myView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, 206)];
    [self.myView setBackgroundColor:[UIColor whiteColor]];
    [self addSubview:self.myView];
    
#warning 修改toolbar 的背景色  加一张白底图片
    //修改背景  需要给出图片
    UIToolbar *pickerDateToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 44)];
    pickerDateToolbar.barStyle = UIBarStyleBlackOpaque;
    [pickerDateToolbar sizeToFit];
    [pickerDateToolbar setBackgroundColor:[UIColor whiteColor]];
    NSMutableArray *barItems = [[NSMutableArray alloc] init];
    
    //
    UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(toolBarCanelClick)];
    [cancelBtn setTintColor:TEXTGREENCOLOR];
    [barItems addObject:cancelBtn];

    
    //
    UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
    [flexSpace setTintColor:TEXTGREENCOLOR];
    [barItems addObject:flexSpace];

    
    //
    UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(toolBarDoneClick)];
    [doneBtn setTintColor:TEXTGREENCOLOR];
    [barItems addObject:doneBtn];

    
    [pickerDateToolbar setItems:barItems animated:YES];
    [self.myView addSubview:pickerDateToolbar];
    
    
    
    [self.gradePicker selectRow:1 inComponent:0 animated:YES];
    [self.myView addSubview:myPick];

}
#pragma mark - 隐藏或显示pickerView
- (void)showMyPicker:(NSInteger)myTag
{
#pragma mark - 一个视图上移  一个不需要  所以我们要分类判断
  
        if (myTag == 124 && self.myGrade == NO) {
            [UIView animateWithDuration:0.2 animations:^{
                if (iPhone6) {
                    self.myView.frame = CGRectMake(0, SCREEN_HEIGHT - 206, SCREEN_WIDTH, 206);
                }
                if (iPhone6Plus) {
                    self.myView.frame = CGRectMake(0, SCREEN_HEIGHT - 206, SCREEN_WIDTH, 206);

                }
                if (iPhone5) {
                    [self.myView setFrame:CGRectMake(0, SCREEN_HEIGHT - 155, SCREEN_WIDTH, 206)];
                }
                
            } completion:^(BOOL finished) {
                self.myGrade = YES;
            }];
        }
        else if(myTag == 125 && self.myBirth == NO)
        {
            [UIView animateWithDuration:0.2 animations:^{
                if (iPhone6Plus) {
                    self.myView.frame = CGRectMake(0, SCREEN_HEIGHT - 255 + 140, SCREEN_WIDTH, 206);
                }
                if (iPhone6) {
                    self.myView.frame = CGRectMake(0, SCREEN_HEIGHT - 255 + 140, SCREEN_WIDTH, 206);
                }
                if (iPhone5) {
                    self.myView.frame = CGRectMake(0, SCREEN_HEIGHT - 255 + 140, SCREEN_WIDTH, 206);
                }
                
            } completion:^(BOOL finished) {
                self.myBirth = YES;
            }];
        }
  
}
- (void)hideMyPicker
{
    [UIView animateWithDuration:0.2 animations:^{
        self.myView.frame = CGRectMake(0, SCREEN_HEIGHT + 300, SCREEN_WIDTH, 206);
    } completion:^(BOOL finished) {
        self.myGrade = NO;
        self.myBirth = NO;
    }];
}
#pragma mark - 这是pickerview里的数据
- (void)createMyGradeData
{
    self.gradeArray = [NSMutableArray array];
    for (int i = 2005; i <= 2024; i++) {
        NSString *grade = [NSString stringWithFormat:@"%d",i];
        [self.gradeArray addObject:grade];
    }
}

- (void)createMyBirthData
{
    self.birthArray = [NSMutableArray array];
    NSMutableArray *yearArray = [NSMutableArray array];
    for (int i = 1970; i < 2025; i++) {
        NSString *year = [NSString stringWithFormat:@"%d年", i];
        [yearArray addObject:year];
    }
    
    NSMutableArray *monthArray = [NSMutableArray array];
    for (int i = 1; i < 13; i++) {
        NSString *month = [NSString stringWithFormat:@"%d月", i];
        [monthArray addObject:month];
    }
    
    NSMutableArray *dayArray = [NSMutableArray array];
    for (int i = 1; i < 32; i++) {
        NSString *day = [NSString stringWithFormat:@"%d日", i];
        [dayArray addObject:day];
    }
    
    [self.birthArray addObject:yearArray];
    [self.birthArray addObject:monthArray];
    [self.birthArray addObject:dayArray];
}


#pragma mark - pickerView的三个方法  和tableview相似
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    if (pickerView == self.gradePicker) {
        return 1;
    }
    else
    {
        return 3;
    }
    
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (pickerView == self.gradePicker) {
        
        return [self.gradeArray count];
    }
    else
    {
        return [[self.birthArray objectAtIndex:component] count];
    }
   
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (pickerView == self.gradePicker) {
        
        return [self.gradeArray objectAtIndex:row];
    }
    else
    {
        NSArray *array = [self.birthArray objectAtIndex:component];
        
        return [array objectAtIndex:row];
    }
   
}

#pragma mark - 自定义pickerView每一行的label
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
   
    UILabel *mycom1 = view ? (UILabel *) view : [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 44)];
    if (pickerView == self.gradePicker) {
        
        self.text = [self.gradeArray objectAtIndex:row];
    }
    else
    {
        NSArray *array = [self.birthArray objectAtIndex:component];
        self.text = [array objectAtIndex:row];
    }
    
    mycom1.text = self.text;
    [mycom1 setFont:[UIFont systemFontOfSize: 17]];
    mycom1.backgroundColor = [UIColor clearColor];
    [mycom1 setTextColor:TEXTGREENCOLOR];
    [mycom1 setTextAlignment:NSTextAlignmentCenter];
    CFShow((__bridge CFTypeRef)(mycom1));
    
    return mycom1;
    
}
#pragma mark - 选中某一行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if (pickerView == self.gradePicker) {
        
        [self.grade setTitle:[self.gradeArray objectAtIndex:row] forState:UIControlStateNormal];
    }
    else
    {
        NSArray *yearArray = [self.birthArray objectAtIndex:0];
        NSArray *monthArray = [self.birthArray objectAtIndex:1];
        NSArray *dayArray = [self.birthArray objectAtIndex:2];
        
        NSInteger yearRow = [self.birthPicker selectedRowInComponent:0];
        NSInteger monthRow = [self.birthPicker selectedRowInComponent:1];
        NSInteger dayRow = [self.birthPicker selectedRowInComponent:2];
        NSString *year = [[yearArray objectAtIndex:yearRow] stringByReplacingOccurrencesOfString:@"年" withString:@""];
        NSString *month = [[monthArray objectAtIndex:monthRow] stringByReplacingOccurrencesOfString:@"月" withString:@""];
        NSString *day = [[dayArray objectAtIndex:dayRow] stringByReplacingOccurrencesOfString:@"日" withString:@""];
        NSString *myText = [NSString stringWithFormat:@"%@-%@-%@", year, month, day];
        [self.birthday setTitle:myText forState:UIControlStateNormal];
    }
   
}

#pragma mark - tooLbar 的点击事件
- (void)toolBarCanelClick
{
    NSLog(@"asda2522222");
    [self hideMyPicker];
    [self viewMoveToOrigin];
}
- (void)toolBarDoneClick
{
    [self viewMoveToOrigin];
    [self hideMyPicker];
  
}
- (void)theirButtonAction:(id)sender
{
   
    [self endEditing:YES];
    UIButton *button = (UIButton *)sender;
    if (button.tag == 124 && self.myGrade == NO) {
        //年级  ,  先返回到原点 在调用显示pickerView的方法
        
        
        if (iPhone5) {
            //视图上移
            [self buttonMoveToUp:(UIButton *)button];
        }
        else
        {
            [self viewMoveToOrigin];
        }
        if (self.myView) {
            [self.myView removeFromSuperview];
            self.myView = nil;
        }
        [self createMyToolBar:self.gradePicker];
        //picker上移
        [self showMyPicker:124];
    }
    else if (button.tag == 125 && self.myBirth == NO) {
        //生日  ,  这里要调用视图上移的方法
        [self buttonMoveToUp:(UIButton *)button];
        if (self.myView) {
            [self.myView removeFromSuperview];
            self.myView = nil;
        }
        [self createMyToolBar:self.birthPicker];
        
        [self showMyPicker:125];
    }
    
}
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    [self hideMyPicker];

    return YES;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self hideMyPicker];
    [self viewMoveToOrigin];
    NSLog(@"end editing");
    
    [self endEditing:YES];
}




#pragma mark - 重写键盘弹出时 输入框上移 方法

// 比键盘弹出先走,textfield开始编辑
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (iPhone5) {
        if (textField.tag == 100 || textField.tag == 102 ) {
            [self viewMoveToOrigin];
            return;
        }
    }
    else
    {
    if (textField.tag == 100 || textField.tag == 101 || textField.tag == 102 ) {
        [self viewMoveToOrigin];
        return;
    }
    }
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    self.editingTextField = textField;
    NSLog(@"editing");
    [self viewMoveToUp];
  
    
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSLog(@"start end editing");
    return YES;
}

- (void)viewMoveToUp
{
//    [self.downView setFrame:CGRectMake(16, self.secondLineHeight, SCREEN_WIDTH - 16, SCREEN_HEIGHT)];
//    [self.downView setBackgroundColor:[UIColor orangeColor]];
    CGFloat differ = 0;
    if (self.editingTextField.tag == 103) {
        
        differ = - 50;
    }
    else
    {
        differ = - self.editingTextField.frame.origin.y - 70;
    }
    //iphone5
    if (iPhone5) {
        if (self.editingTextField.tag == 103) {
            
            differ = - 150;
        }
        else if(self.editingTextField.tag == 101)
        {
            differ = - 80;
        }
        else if(self.editingTextField.tag == 501)
        {
            differ = - self.editingTextField.frame.origin.y - 130;
        }
        else
        {
            differ = - self.editingTextField.frame.origin.y - 170;
        }

    }
    
    
    [UIView animateWithDuration:0.2 animations:^{
        [self setFrame:CGRectMake(0,  differ, SCREEN_WIDTH, SCREEN_HEIGHT)];
    } completion:^(BOOL finished) {
       
    }];

}

- (void)viewMoveToOrigin
{
    
    [UIView animateWithDuration:0.1 animations:^{
        [self setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    } completion:^(BOOL finished) {
       [[UIApplication sharedApplication] setStatusBarHidden:NO];
    }];

}

- (void)buttonMoveToUp:(UIButton *)button
{
//    UIButton *button = (UIButton *)[self viewWithTag:125];
    
    CGFloat differ = - (button.frame.origin.x + 90);

    if (button.tag == 124 && iPhone5) {
        differ = - (button.frame.origin.x + 50);

    }
    
    [UIView animateWithDuration:0.2 animations:^{
        [self setFrame:CGRectMake(0,  differ, SCREEN_WIDTH, SCREEN_HEIGHT + 200)];
    } completion:^(BOOL finished) {
        
    }];
}

- (CGFloat)getHeightOfProfile
{
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, nil];

    CGRect rect = [[self.myDic objectForKey:@"profile"] boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 32, 10000) options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:dic context:nil];

    return rect.size.height;
}



@end
